#include "stdafx.h"
#using<system.dll>
namespace Prueba
{

// text_read.cpp
// compile with: /clr

//
using namespace System;
using namespace System::IO;

int read(String ^fileName)
{
   //String^ fileName = "textfile.txt";
   try 
   {
      Console::WriteLine("trying to open file {0}...", fileName);
      StreamReader^ din = File::OpenText(fileName);

      String^ str;
      int count = 0;
      while ((str = din->ReadLine()) != nullptr) 
      {
         count++;
         Console::WriteLine("line {0}: {1}", count, str );
      }
   }
   catch (Exception^ e)
   {
      if (dynamic_cast<FileNotFoundException^>(e))
         Console::WriteLine("file '{0}' not found", fileName);
      else
         Console::WriteLine("problem reading file '{0}'", fileName);
   }

   return 0;
};
}